from PyQt5.QtWidgets import *
from PyQt5.QtCore import Qt,QSize,pyqtSignal,QTimer,QRect


class ConfigLabelDisp(QWidget):

    sig_configTextUpdata  = pyqtSignal(object)

    def __init__(self,tabWidget,config):
        super(ConfigLabelDisp, self).__init__()
        self.tabWidget = tabWidget
        self.config = config
        self.lbl_short_list = []
        self.lbl_list = []
        self.ldt_list = []

        #self.lab_num = 160      # 从配置文件中获取监控的变量的个数

        self.topFiller = QWidget()
        self.topFiller.resize(self.tabWidget.width()-20, 2000)

        self.scroll = QScrollArea(self.tabWidget)
        self.scroll.setWidget(self.topFiller)
        self.scroll.setMinimumSize(self.tabWidget.width()-20,self.tabWidget.height())

    # 获取串口接收并解析后的数据显示出来
    def slotDispText(self,frameEleList):
        print("LabelDisp frameEleList:",frameEleList)
        for i in range(len(frameEleList)): 
            self.ldt_list[i].setText(str(frameEleList[i]) + ":" + str(i))

    # 创建显示标签
    def createDispLable(self):
        type = self.config["frameType"]["1"]
        for short_i in list(self.config[type]["element_dict"].keys()):
            lbl_short_new = QLabel(self.topFiller)
            self.lbl_short_list.append(lbl_short_new)
            self.lbl_short_list[-1].setObjectName("lbl_short_new" + short_i)
            self.lbl_short_list[-1].setText(short_i + ':')
            self.lbl_short_list[-1].setFixedWidth(100)        

    def lableDispLayout(self):
        self.topFiller.resize(self.tabWidget.width()-20, 2000)
        self.scroll.setMinimumSize(self.tabWidget.width(),self.tabWidget.height())
        short_i = 0
        for num in range(0,len(self.lbl_short_list)):   
            print("short_i,num",short_i,num)       
            self.lbl_short_list[num].setGeometry(QRect(10, 10+short_i*30, self.lbl_short_list[num].width(), 20))
            short_i += 1









